package supershop.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import supershop.dao.IOrderDetailDao;
import supershop.dao.IOrdersDao;
import supershop.dto.OrdersDTO;
import supershop.model.OrderDetail;
import supershop.model.Orders;

@Controller
@RequestMapping("/admin/start/orders")
public class OrdersController {

	@Resource
	private IOrdersDao ordersDao;
	@Resource
	private IOrderDetailDao orderDetailDao;
	//查询所有订单
	@RequestMapping("/findAll.do")
	@ResponseBody
	public Map findAll(OrdersDTO dto) {
		List<Orders> list = ordersDao.findAll(dto);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("code", 0);
		map.put("count", ordersDao.getCount(dto));
		map.put("data", list);
		return map;
	}
	
	//查看订单详情
	@RequestMapping("/findOrderDetail.do")
	@ResponseBody
	public Map findOrderDetail(int oid) {
		List<OrderDetail> list = orderDetailDao.findByOID(oid);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("count", list.size());
		map.put("data", list);
		return map;
	}
	
	//发货
	@RequestMapping("/send.do")
	@ResponseBody
	public int send(int id) {
		return ordersDao.deliver(id);
	}
	

}
